#ifndef ENTENSIBLEHASH_H_
#define ENTENSIBLEHASH_H_
#include "../Record.h"
#include "../../Managers/BlockFileManager.h"
#include "Bucket.h"
#include <fstream>   // Biblioteca para el manejo de ficheros
#include <iostream> // Biblioteca para la entrada-salida estándar
#include <string>
#include <math.h>
#include <vector>
#include "../../Commons/Configuration.h"
using namespace std;

class ExtensibleHash {
private:
	int* table;
	BlockFileManager * blockFile;
	int applyHashFuction(string key,int td);
	int canReleaseBlock(int position,int td);
	void duplicateTable();
	int getTableSize();
	int getPositionNewBlock();
	void writeTableFile();
	void readTableFile();
	void truncateTable();
	int loadPercentage;
	fstream hashTable;
	int tableSize;

public:
	ExtensibleHash(string name);
	void insertRecord(Record *newRecord);
	void deleteRecord(Record* record);
	Record * searchRecord(string Key);
	void reDisperse(vector<Record*>* records, Record* newRecord);
	void updateTable(int position, int td, int blockNumber);
    void getDispersion();
    void setDispersion();
    void exportToTxt(string name);
	virtual ~ExtensibleHash();
};

#endif /* ENTENSIBLEHASH_H_ */
